package org.lcb.demo.shiyan3.controller;

import org.lcb.demo.shiyan3.result.Result;
import org.lcb.demo.shiyan3.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pojo.Product;

import java.util.List;

@RestController
@RequestMapping("/product")
public class ProductController {
    @Autowired
    ProductService productService;
    @GetMapping("/detail/{id}")
    public Result<Product> getProductById(@PathVariable int id){
        Product product = productService.getProductById(id);
        return Result.success(product);
    }
    /*
    * 根据产品的种类查询
    * */
    @GetMapping("/{categoryId}")
    public Result<List<Product>> getProductByCategoryId(@PathVariable int categoryId){
        List<Product> products = productService.getProductByCategoryId(categoryId);
        return Result.success(products);
    }

    @GetMapping()
    public Result<List<Product>> getProductList(){
        List<Product> list = productService.getProductList();
        return Result.success(list);
    }







}
